const { UI_Layer, UI_Listen } = require("../../config/ui_def");

cc.Class({
    extends: cc.Component,

    properties: {
        music_toggle: cc.Toggle,
    },
    initPage(){},
    updatePage(){
        gg.data.pause = true
        this.showVoiceStatus()
    },
    restartGame(){
        this.uiBase.closePage()
        gg.uiManager.addPage(UI_Layer.Load, {
            name: "LoadCover",
            in: true,
            restart: true,
            scene: 'Playground'
        })
        gg.eventManager.emit('loadcover', UI_Listen.CLOSE_LOAD_COVER)
        
    },
    exitGame(){
        gg.uiManager.addPage(UI_Layer.Load, {
            name: "LoadCover",
            in: true,
            scene: 'Main'
        })
    },
    showVoiceStatus(){
        let setting = he.local.getJson("setting")
        if(setting.music_switch){
            this.music_toggle.isChecked = false
        }else{
            this.music_toggle.isChecked = true
        }
    },
    switchVoice(){
        let setting = he.local.getJson("setting")
        if(setting.music_switch){
            setting.music_switch = false
            setting.effect_switch = false
            this.music_toggle.isChecked = true
            he.voice.pauseVoice(true)
        }else{
            setting.music_switch = true
            setting.effect_switch = true            
            this.music_toggle.isChecked = false
            he.voice.pauseVoice(false)
        }
        he.local.setJson("setting",setting)
    },
    closeUI(){
        gg.data.pause = false
    }
});
